package com.edwarder.web.film;

import com.edwarder.entity.Film;
import com.edwarder.service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: jzhang
 * @Date: 2018/10/23 22:33
 * @Description:
 */
@Controller
@RequestMapping("/a/film")
public class FilmController {
    @Autowired
    private FilmService filmService;

    @RequestMapping("/list")
    public String list(Model model, Integer page, Integer size) {
        List<Film> list = filmService.findList(page,size);
        model.addAttribute("films",list);
        return "film/filmList";
    }

    @RequestMapping("/form")
    public String form(Film film,Model model) {
        film = filmService.findByPrimaryKey(film);
        model.addAttribute("film",film);
        return "film/filmForm";
    }

    @RequestMapping("/save")
    @ResponseBody
    public String save(Film film) {
        filmService.saveFilm(film);
        return "success";
    }

}
